#===============================================================================
# Run all R script files to reproduce the figures and tables
#===============================================================================

# File:	    0_master.R
# Project:	Colonial legacy and foreign aid: Decomposing the colonial bias
# Authors:	Daina Chiba, Department of Government, University of Essex
#           Tobias Heinrich, Department of Political Science, University of South Carolina
# Contact:	dchiba@essex.ac.uk
# Date:     20 November, 2018
# Program:  R version 3.5.1 (2018-07-02)
# Packages: stargazer (ver 5.2.2), MCMCglmm (ver 2.26), texreg (1.36.23),
#           ggplot2 (ver 3.1.0), countrycode (ver 1.1.0), gmodels (ver 2.18.1)


# Description: 
# This master R script file runs all the R script files in the replication archive.
# Before running this file, set the working directory to the "replication" folder
# that contains all the R script files included in replication.zip.

setwd("YOUR_PATH_TO_REPLICATION/replication")

# The commands below create subdirectories to store all the outputs. 
# Those outputs we report in our article are stored in "output_original.zip".

dir.create("output")
dir.create("output/figures")
dir.create("output/tables")
dir.create("output/mcmc")

# Install necessary packages
install.packages("stargazer", dependencies = TRUE)
install.packages("MCMCglmm", dependencies = TRUE)
install.packages("texreg", dependencies = TRUE)
install.packages("ggplot2", dependencies = TRUE)
install.packages("countrycode", dependencies = TRUE)
install.packages("gmodels", dependencies = TRUE)

# 1. Synthetic data exercise
source("1_SimulatedData.R")

# 2. Left-hand side of Table 2 and Figure 2 (Without controls).
source("2_Table2a-withoutC.R")

# 3. Right-hand side of Table 2 and Figure 2 (With controls).
source("3_Table2b-withC.R")

# 4. Left-hand side of Table A.3 and Figure A.3 (With controls).
source("4_TableA3a-withoutC.R")

# 5. Right-hand side of Table A.3 and Figure A.3 (With controls).
source("5_TableA3b-withC.R")

# 6. Figures A.4 and A.5 in Appendix F. 
source("6_FigureA4-A5_nevercolonized.R")

# 7. Table A4 and Figure A.6 in Appendix G. 
source("7_TableA4a_nonlogged.R")

# 8. Table A4 and Figure A.6 in Appendix G (alternative specification)
source("8_TableA4b_nonlogged.R")

# 9. Figures A.7 - A.10 in Appendix H and I.
source("9_FigureA7-A10a_spec1.R")

# 10. Figures A.7 - A.10 in Appendix H and I (alternative specification). 
source("10_FigureA7-A10b_spec2.R")

# 11. descriptive statistics results reported in Appendix C (Figures A.1 & A.2 and Table A.2).
source("11_descriptive.R")


# End of file
